//createRouter 用于创建vue-router实例对象
//createWebHistory 用于指定路由的工作模式
//RouteRecordRaw 用于规范路由规则,增加路由对象类型限制
import { createRouter, createWebHistory,RouteRecordRaw } from 'vue-router'
import HomeView from '../views/HomeView.vue'
//创建路由规则 
const routes:Array<RouteRecordRaw> = [
  {
    path:'/',
    component:import('../views/HomeView.vue')
  }
]
//路由实例对象
const router = createRouter({
  
  history: createWebHistory(),
  routes
})
//路由导航守卫
router.beforeEach((to,from,next)=>{
  const store = useStore()
  if(store.token){
    next()
  }else{
    next(to.path)
  }
})
export default router
